import {get,post} from '../../http'

const CLASSLIST = 'CLASSLIST';
const ADDCLASSONE = 'ADDCLASSONE'
const HUOZHU = 'HUOZHU'
const HUOZHONG = 'HUOZHONG'
const DIDIAN = 'DIDIAN'
const ADDCLASSONE2 = 'ADDCLASSONE2'
const TRANSOIRTLIST = 'TRANSOIRTLIST'

const initState={
	transportData:{},
	addClass2:false,
	goodsList:{},
	huoZhuList:{},
	logisticsList:{},
	queryList:{},
	addCJ:false
	
}

// reducer1
export function transport(state=initState, action){
	switch(action.type){
		case CLASSLIST:
			return Object.assign({},state,{transportData:action.data,addClass2:false,addCJ:false})
		case ADDCLASSONE:
			return Object.assign({},state,{addClass2:action.res})
		case HUOZHU:
			return Object.assign({},state,{huoZhuList:action.data})
		case HUOZHONG:
			return Object.assign({},state,{goodsList:action.data})
		case DIDIAN:
			return Object.assign({},state,{logisticsList:action.data})
		case ADDCLASSONE2:
			return Object.assign({},state,{addCJ:action.res})
		case TRANSOIRTLIST:
			return Object.assign({},state,{queryList:action.data,addCJ:false})
		default:
			return state
	}
} 



function transportListSuccess(data){
	return {type:TRANSOIRTLIST,data:data}
}

function transportClassSuccess(data){
	
	return {type:CLASSLIST,data:data}
}
function huoZhuSuccess(data){
	console.log(data)
	return {type:HUOZHU,data:data}
}
function huoZhongSuccess(data){
	return {type:HUOZHONG,data:data}
}
function diDianSuccess(data){
	return {type:DIDIAN,data:data}
}
function AddclassClassSuccess(res){
	return {type:ADDCLASSONE,res:res}
}
function AddclassClassSuccess1(res){
	return {type:ADDCLASSONE2,res:res}
}

export function TransportAddClass2(planName,goodsId,huoZhuId,original,destination,planTonnage,planStartDate,startDateRange,planEndDate,endDateRange){
	let data ={
		planName:planName,
		transportState:'0',
		goodsId : goodsId,
		huoZhuId : huoZhuId,
		original : original,
		destination : destination,
		planTonnage : planTonnage,
		planStartDate : planStartDate,
		startDateRange : startDateRange,
		planEndDate : planEndDate,
		endDateRange : endDateRange
	}
	return dispatch=>{
		post('/transportPlan/addTransportPlan.do',data)
			.then(res=>{
					dispatch(AddclassClassSuccess1(res.SUCCESS));
			})		
	}
	
}

export function TransportAddClass(className){
	return dispatch=>{
		post('/transportPlan/addTransportPlanClass.do',{className:className})
			.then(res=>{
					dispatch(AddclassClassSuccess(res.SUCCESS));
			})		
	}
	
}

export function transportList(transportState){
	let data = {
		transportState:transportState
	}
	return dispatch=>{
		post('/transportPlan/queryTransportPlan.do',data)
			.then(res=>{
					dispatch(transportListSuccess(res.List));
			})		
	}
	
}

export function TransportClassList(){
	return dispatch=>{
		post('/transportPlan/queryTransportPlanClass.do',{})
			.then(res=>{
					dispatch(transportClassSuccess(res.data));
			})		
	}
	
}

export function huoZhuList(){
	return dispatch=>{
		post('config/queryHuoZhuConfig.do',{})
			.then(res=>{
					dispatch(huoZhuSuccess(res.huoZhuList));
			})		
	}
	
}

export function huoZhongList(){
	return dispatch=>{
		post('config/queryGoodsConfig.do',{})
			.then(res=>{
					dispatch(huoZhongSuccess(res.goodsList));
			})		
	}
	
}

export function diDianClassList(){
	return dispatch=>{
		post('config/queryLogisticsConfig.do',{})
			.then(res=>{
					dispatch(diDianSuccess(res.logisticsList));
			})		
	}
	
}

